package com.gameShare.controller.misc

import com.gameShare.controller.base.LoginVerifyController
import com.gameShare.entity.dto.game.GameCommentDto
import com.gameShare.entity.dto.user.UserCenterCommentDto
import com.gameShare.entity.vo.PageVo
import com.gameShare.entity.vo.ResponseVo
import com.gameShare.service.game.GameCommentService
import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.constraints.NotEmpty
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("comment")
@Validated
open class CommentController(
        private val commentService: GameCommentService,
    ) : LoginVerifyController() {

    /**
     * 加载游戏评论页
     *
     * @param gameId 游戏id
     * @param pageNo 页面数量
     * @param pageSize 页面大小
     * @return
     */
    @RequestMapping("loadGameCommentPage")
    open fun loadGameCommentPage(@NotEmpty gameId : String,pageNo : Int?, pageSize : Int?): ResponseVo<PageVo<GameCommentDto?>> {
        return getSuccessResponseVO(commentService.getGameTreeCommentPage(gameId, pageNo, pageSize))
    }

    /**
     * 上传评论
     *
     * @param httpServletRequest 携带token
     * @param gameId 游戏id
     * @param pCommentId 父评论id
     * @param content 内容
     * @return
     */

    @PostMapping("postComment")
    open fun postComment(
        httpServletRequest: HttpServletRequest,
        @NotEmpty gameId : String, pCommentId : Int?,
        @NotEmpty content : String): ResponseVo<Boolean> {
        commentService.postGameComment(
            gameId,
            getUserIdByToken(httpServletRequest),
            pCommentId,
            content)
        return getSuccessResponseVO(true)
    }

    /**
     * 加载用户评论页
     * @param httpServletRequest 携带token
     * @param pageNo 页数
     * @param pageSize 页面大小
     */
    @RequestMapping("loadUserCommentPage")
    open fun loadUserCommentPage(httpServletRequest: HttpServletRequest, pageNo: Int?, pageSize: Int?): ResponseVo<PageVo<UserCenterCommentDto?>> {
        return getSuccessResponseVO(
            commentService.getUserCommentPage(
                getUserIdByToken(httpServletRequest),
                pageNo,
                pageSize
            )
        )
    }

}